package org.liquidByte.trafficMustang.androidApp.overlays;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public abstract class SingleMarkerOverlay extends Overlay {
	private Bitmap pushpin;
	private GeoPoint mark;
	
	protected SingleMarkerOverlay(Bitmap pushpin) {
		super();
		if (pushpin == null) {
			throw new IllegalArgumentException("pushpin is null");
		}
		this.pushpin = pushpin;
	}
	
	protected Bitmap getPushpin() {
		return pushpin;
	}
	
	public GeoPoint getMark() {
		return mark;
	}
	
	protected void setMark(GeoPoint mark) {
		this.mark = mark;
	}
	
	@Override
	public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
		boolean ret = super.draw(canvas, mapView, shadow, when);
		
		if (this.mark != null) {
			Bitmap pushpin = this.getPushpin();
			Point drawingPoint = new Point();
			mapView.getProjection().toPixels(this.mark, drawingPoint);
			
			drawingPoint.y = drawingPoint.y - pushpin.getHeight(); 
			
			canvas.drawBitmap(this.getPushpin(), drawingPoint.x, drawingPoint.y, null);
		}
		
		return ret;
	}
}